//
//  CustomGridView.h
//  TAOVideo
//
//  Created by Lin Eidan on 13-8-7.
//  Copyright (c) 2013年 taomee. All rights reserved.
//

#import <UIKit/UIKit.h>
#import "CustomTableCell.h"

@protocol CustomGridViewDelegate;
@protocol CustomGridViewDataSource;

@interface CustomGridView : UIScrollView<UIScrollViewDelegate>

@property (strong, nonatomic) UIView *mainGridView;
@property (weak, nonatomic) id<CustomGridViewDelegate>customGridViewdelegate;
@property (weak, nonatomic) id<CustomGridViewDataSource>customGridViewdataSource;

@property(assign, nonatomic) NSUInteger numsOfColumn;  //列数
@property(strong, nonatomic) NSMutableArray *cellRectArray;
@property(strong, nonatomic) NSMutableArray *visibleCellsArray;
@property(strong, nonatomic) NSMutableDictionary *reuseCellsDic;

//@property(assign, nonatomic) float ySpace;      //高度间隙
@property(assign, nonatomic) float xSpace;      //列与列之间的间隙

//@property(assign, nonatomic) BOOL isNowReloadData;

-(CustomTableCell *)dequeueReusableCellWithIdentifier:(NSString *)identifier;
-(void)reloadData;
-(void)onScroll;

-(CustomTableCell *)getCellWithIndexPath:(CustomIndexPath *)indexPath;

//在GridView前面加视图
-(void)drawOtherViewBeforeGridView:(UIView *)otehrView andGridViewTop:(float )gridViewTop;

-(void)drawOtherViewInGridView:(UIView *)otehrView;

//调整GridView的left
-(void)setGridViewLeft:(float)gridViewLeft;

//空间改变大小后，子视图跟着改变，且离父视图的left保持不变。
-(void)resetWidthWithSubViews;



//-----------------------------------------------------------编辑模式 start-----------------------------------
@property(assign, nonatomic) BOOL isInEditingMode;
@property(strong, nonatomic) NSMutableArray *hasSelectedArray;

//进入编辑模式
-(void)customGridViewSetEdit:(BOOL)edit andAnimation:(BOOL)animation;

//索引为index的是否在选择数组里。。
-(BOOL)theCellIsInTheHasSelectedArray:(int )index;

//全选,反选
-(void)customGridViewSelectAllOrNot:(BOOL)isSelectedAll andArrayCount:(int )count;

//-----------------------------------------------------------编辑模式 end-----------------------------------


@end

@protocol CustomGridViewDataSource <NSObject>

@required
-(NSInteger)numberOfColumnsInCustomGridView:(CustomGridView *)customGridView;  //有多少列
-(NSInteger)customGridView:(CustomGridView *)customGridView numberOfRowsInColumn:(NSInteger)column;  //每一列有多少个cell
-(CGFloat)customGridView:(CustomGridView *)customGridView widthOfColumn:(NSInteger)column;  //每一列的宽度
-(CGFloat)customGridView:(CustomGridView *)customGridView heightForCellsAtIndexPath:(CustomIndexPath *)indexPath;  //每一个cell的高度
-(CGFloat)customGridView:(CustomGridView *)customGridView topSpaceForCellsAtIndexPath:(CustomIndexPath *)indexPath;  //每一个cell前面的间隙。。
-(CustomTableCell *)customGridView:(CustomGridView *)customGridView cellAtIndexPath:(CustomIndexPath *)indexPath; //每一个cell

@end

@protocol CustomGridViewDelegate <NSObject>

@optional
- (void)customGridViewDidScroll:(CustomGridView *)customGridView;
- (void)customGridViewDidEndDecelerating:(CustomGridView *)customGridView;
- (void)customGridViewDidEndDragging:(CustomGridView *)customGridView willDecelerate:(BOOL)decelerate;
@end